package com.example.message.response;

public enum ResponseCodeEnum {
    /**
     * 成功状态码
     */
    //成功
    SUCCESS(0, "成功"),
    FAILURE(-1, "失败"),
    /**
     * 参数错误：10001-19999
     */
    //参数无效
    PARAM_IS_INVALID(10001, "参数无效"),
    //参数为空
    PARAM_IS_BLANK(10002, "参数为空"),
    //参数类型错误
    PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
    //参数缺失
    PARAM_NOT_COMPLETE(10004, "参数缺失"),
    //参数错误
    PARAM_IS_ERROR(10005,"参数错误"),

    /**
     * 用户错误：20001-29999
     */
    //用户未登录
    USER_NOT_LOGGED_IN(1001, "用户未登录"),
    //账号不存在或密码错误
    USER_LOGIN_ERROR(1003, "账号不存在或密码错误"),
    // 修改密码错误
    USER_PASSWORD_ERROR(1004, "密码错误");

    private Integer code;
    private String messageCode;
    ResponseCodeEnum(Integer code, String messageCode){
        this.code = code;
        this.messageCode = messageCode;
    }
    public Integer code(){
        return this.code;
    }
    public String message(){
        return this.messageCode;
    }
    public static String getMessage(String name) {
        for (ResponseCodeEnum item : ResponseCodeEnum.values()) {
            if (item.name().equals(name)) {
                return item.messageCode;
            }
        }
        return name;
    }
    public static Integer getCode(String name){
        for (ResponseCodeEnum item : ResponseCodeEnum.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }
    @Override
    public String toString() {
        return "ResponseCodeEnum{" +
                "code=" + code +
                ", messageCode='" + messageCode + '\'' +
                '}';
    }
}